package com.fz.us.admin.base.bean.search.page;

import com.fz.us.admin.base.bean.search.SearchEnum;
import com.fz.us.admin.base.bean.search.projection.Projection;
import com.fz.us.admin.base.bean.search.projection.ProjectionHelp;
import org.springframework.util.Assert;

/**
 * 查询 - 参数 - PageUnique
 * ============================================================================
 * 版权所有 2016 。
 *
 * @author fallenpanda
 * @version 1.0 2016-07-13 。
 * ============================================================================
 */
public class PageUnique extends Page {

    private PageUnique(SearchEnum.ResultType resultType, Projection projection) {
        super(resultType, projection);
    }

    public static PageUnique uniqueResult() {
        return newBuilder().setResultType(SearchEnum.ResultType.uniqueResult).setProjection(ProjectionHelp.none()).build();
    }

    public static PageUnique uniqueResult(Projection projection) {
        return newBuilder().setResultType(SearchEnum.ResultType.uniqueResult).setProjection(projection).build();
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public static class Builder extends Page.Builder<Page, Builder> {

        @Override
        protected Builder getThis() {
            return this;
        }

        @Override
        public PageUnique build() {
            Assert.notNull(resultType, "resultType 不能为空");
            Assert.notNull(projection, "projection 不能为空");
            return new PageUnique(resultType, projection);
        }

    }

}
